// VUE 全家桶
import Router from '_router/router'

// 自定义方法
import { isLoginChose } from '_projectFn/login'
import { objToStr } from '_commonFn/object'

export const toIndex = ({callback}) => {
    if (process.env.IS_LOCAL) {
        Router.push({
            path: `Home`,
            name: 'Home'
        })
        typeof callback === 'function' && callback(true)
    } else {
        window.location.href = '../index.html'
    }
}

// 进入个人设置页面
export const enterUserSet = (option = '', url = location.href.split('#')[0]) => {
    if (isLoginChose(url)) {
        if (process.env.IS_LOCAL) {
            // 未开发个人设置页面
            console.log('未开发个人设置页面')
            return
        } else {
            const optionUrlParam = option ? `?option=${option}` : ''
            window.location.href = `../user-accountManagement.html${optionUrlParam}`
        }
    }
}

// 进入设置支付密码页面
export const enterUserSetPayPassword = () => {
    if (process.env.IS_LOCAL) {
        // 未开发设置支付密码页面
        console.log('未开发设置支付密码页面')
        return
    } else {
        sessionStorage.setItem('accountManagementOption', 'safty')
        window.location.href = `../user-accountManagement.html`
    }
}

// 进入业务详情页面
export const enterUserBus = ({type = 'userIndex', userId = '', checkLogin = true}) => {
    console.log('checkLogin', checkLogin)
    if (userId) {
        if (checkLogin) {
            if (isLoginChose()) {
                Router.push({
                    path: 'UserBus',
                    name: 'UserBus',
                    query: {
                        type,
                        userId
                    }
                })
            }
        } else {
            Router.push({
                path: 'UserBus',
                name: 'UserBus',
                query: {
                    type,
                    userId
                }
            })
        }
    }
}

// 进入微信群详情页面
export const enterWechatGruopDetail = ({isOuter = 0, wechatGroupNo, type}) => {
    if (process.env.IS_LOCAL) {
        console.log('未开发微信群详情页面')
    } else {
        window.location.href = `../web-wechat-group.html?type=${type}&relNo=${wechatGroupNo}&relType=${isOuter}`
    }
}

// 进入个人主页
export const enterUserIndex = ({type = 'normal', userId}) => {
    // if (isLoginChose()) {
    //     if (userId) {
    //         if (process.env.IS_LOCAL) {
    //             console.log('未开发个人主页')
    //         } else {
    //             window.location.href = `../user-index.html?type=${type}&userId=${userId}`
    //         }
    //     }
    // }
    Router.push({
        path: 'UserIndex',
        name: 'UserIndex',
        query: {
            userId
        }
    })
}

// 点击返回
export const backHistory = () => {
    if (process.env.IS_LOCAL) {
        if (window.history.length > 1) {
            Router.go(-1)
        } else {
            Router.push({
                path: '',
                name: 'Home'
            })
        }
    } else {
        if (window.history.length > 1) {
            Router.go(-1)
        } else {
            window.location.href = '../index.html'
        }
    }
}

export const loadService = () => {
    var hm = document.createElement("script")
    hm.src = "https://hm.baidu.com/hm.js?a01ef2b819e4f8fa88ed9208da21a8ea"
    document.head.appendChild(hm)
}

// 进入业务人员列表页面
export const enterBusMemberList = () => {
    Router.push({
        path: 'MemberBusList',
        name: 'MemberBusList'
    })
}

// 进入评论页面
export const enterLeaveMessage = (data) => {
    // console.log('objToStr(data)', objToStr(data))
    if (process.env.IS_LOCAL) {
        console.log('未开发留言页面')
    } else {
        window.location.href = `../association-leave-message.html${objToStr(data)}`
    }
}

// 进入资金明细
export const enterPriceDetail = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发资金明细页面')
        } else {
            window.location.href = `../user-accound-detail.html`
        }
    }
}

// 进入积分明细
export const enterUserIntegral = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发积分明细页面')
        } else {
            window.location.href = `../user-integral.html`
        }
    }
}

// 进入贡献分明细
export const enterContributionDetail = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发贡献分明细页面')
        } else {
            window.location.href = `../user-contribution.html`
        }
    }
}

// 进入关注页面
export const enterUserFollow = (option) => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发关注页面')
        } else {
            if (option) {
                sessionStorage.setItem('userWatchfulSelectOption', option)
            }
            location.href = `../user-watchful.html`
        }
    }
}

// 进入收藏页面 
export const enterUserCollect = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发收藏页面')
        } else {
            window.location.href = `../user-collect.html`
        }
    }
}

// 进入账号信息、关注设置、业务名片
export const enterUserAccSet = (option) => {
    // console.log('option', option)
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发账号信息、关注设置、业务名片页面')
        } else {
            let queryStr = ''
            if (option) {
                queryStr = `?option=${option}`
            }
            location.href = `../user-accountManagement.html${queryStr}`
        }
    }
}

// 进入我的社群页面
export const enterUserAsList = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发我的社群页面')
        } else {
            window.location.href = `../user-association.html`
        }
    }
}

// 进入我的主讲页面
export const enterUserWrokshopList = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发我的主讲页面')
        } else {
            window.location.href = `../user-workshop.html`
        }
    }
}

// 进入我的微信群页面
export const enterUserWechatList = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发我的微信群页面')
        } else {
            window.location.href = `../user-wechat-list.html`
        }
    }
}

// 进入积分榜页面
export const enterInstral = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发积分榜页面')
        } else {
            window.location.href = `../integral-list.html`
        }
    }
}

// 点击显示客服
export const showService = () => {
    document.getElementById('nb_icon_wrap').click()
}

// 进入主讲详情页面
export const enterWorkshopDetail = ({
    seminarNo,
    groupNo,
    type = 'userIndex',
}) => {
    if (process.env.IS_LOCAL) {
        console.log('未开发主讲详情页面')
    } else {
        window.location.href = `../association-workshop-content.html?type=${type}&seminarNo=${seminarNo}&groupNo=${groupNo}`
    }
}

// 进入社群详情页面
export const enterAsDetail = ({
    asNo,
    associationType,
    type = 'userIndex',
}) => {
    if (process.env.IS_LOCAL) {
        console.log('未开发社群详情页面')
        // window.location.href = `${process.env.URL}/association-content.html?type=${type}&No=${asNo}${associationType}`
    } else {
        associationType = associationType ? `&associationType=${associationType}` : ''
        window.location.href = `../association-content.html?type=${type}&No=${asNo}${associationType}`
    }
}

// 进入关于页面
export const enterAbout = () => {
    Router.push({
        path: 'About',
        name: 'About'
    })
}

// 进入首次设置页面（登录密码、手机）
export const enterFirstSetting = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发首次设置页面')
        } else {
            window.location.href = '../user-reset-phone-ps.html'
        }
    }
}

// 进入设置密码页面
export const enterUserSetLoginPwd = (isSetPwd) => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发设置登录密码页面')
        } else {
            window.location.href = `../user-reset-password.html?Tag=${isSetPwd ? 1 : 0}`
        }
    }
}

// 进入设置支付密码页面 enterUserSetPayPwd
export const enterUserSetPayPwd = (isSetPwd) => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发设置支付密码页面')
        } else {
            window.location.href = `../user-reset-paypassword.html?Tag=${isSetPwd ? 1 : 0}`
        }
    }
}

// 进入设置手机号码页面
export const enterUserSetPhone = (isSet, phoneNum) => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发设置手机号码页面')
        } else {
            const phone = isSet ? `?Phone=${phoneNum}` : ''
            window.location.href = `../user-reset-phone.html${phone}`
        }
    }
}

// 进入设置邮箱页面
export const enterUserSetEmail = () => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发设置邮箱页面')
        } else {
            window.location.href = `../user-reset-email.html`
        }
    }
}

// 进入关注页面
export const enterFollow = (option = '') => {
    if (isLoginChose()) {
        if (process.env.IS_LOCAL) {
            console.log('未开发关注页面')
        } else {
            if (option) {
                sessionStorage.setItem('userWatchfulSelectOption', option)
            }
            window.location.href = `../user-watchful.html`
        }
    }
}